import inherits from 'inherits'
import Vue from 'vue'
import CamundaPropertiesProvider from 'bpmn-js-properties-panel/lib/provider/camunda/CamundaPropertiesProvider'

export default function MagicPropertiesProvider (
  eventBus, bpmnFactory, elementRegistry, elementTemplates,
  translate) {
  CamundaPropertiesProvider.call(this, eventBus, bpmnFactory, elementRegistry, elementTemplates, translate)
  const superTabs = this.getTabs
  this.getTabs = function (element) {
    const tabs = superTabs(element)
    tabs.forEach(tab => {
      if (tab.id === 'general') {
        tab.groups.forEach(group => {
          if (group.id === 'candidateStarterConfiguration' || group.id === 'details') {
            if (group.entries.length > 0) {
              let tag = true
              Vue.prototype.bpmn.forEach(item => {
                if (item.id === element.id) {
                  tag = false
                }
              })
              if (tag) {
                Vue.prototype.bpmn.push(element)
              }
            }
          }
        })
      } else if (tab.id === 'forms') {
        tab.groups.forEach(group => {
          if (group.id === 'forms') {
            const temps = group.entries.filter(entry => {
              return entry.id === 'form-key'
            })

            if (temps.length === 1) {
              group.entries = temps
            }
          }
        })
      }
    })
    return tabs
  }
}
MagicPropertiesProvider.$inject = [
  'eventBus',
  'bpmnFactory',
  'elementRegistry',
  'elementTemplates',
  'translate'
]
inherits(MagicPropertiesProvider, CamundaPropertiesProvider)
